import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { getSerialAvailable } from './serial.api';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { buildUUID } from '/@/utils/uuid';

export const columns: BasicColumn[] = [
  {
    title: '串口名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '串口',
    dataIndex: 'com',
    width: 100,
  },
  {
    title: '波特率',
    dataIndex: 'baudRate',
    width: 120,
  },
  {
    title: '数据位',
    dataIndex: 'dataBits',
    width: 80,
  },
  {
    title: '校验位',
    dataIndex: 'parity',
    width: 100,
  },
  {
    title: '停止位',
    dataIndex: 'stopBits',
    width: 100,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 100,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '串口名称',
    field: 'name',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '串口状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'iot_device_status',
      placeholder: '请选择串口状态',
      stringToNumber: false,
    },
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '串口名称',
    field: 'name',
    component: 'Input',
    required: true,
  },
  {
    label: '串口',
    field: 'com',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: getSerialAvailable,
      labelField: 'label',
      valueField: 'value',
      getPopupContainer: () => document.body,
    },
  },
  {
    label: '波特率',
    field: 'baudRate',
    component: 'InputNumber',
    defaultValue: 9600,
    required: true,
  },
  {
    label: '数据位',
    field: 'dataBits',
    component: 'InputNumber',
    defaultValue: 8,
    required: true,
  },
  {
    label: '停止位',
    field: 'stopBits',
    component: 'InputNumber',
    defaultValue: 1,
  },
  {
    label: '校验位',
    field: 'parity',
    component: 'InputNumber',
    defaultValue: 0,
  },
];